﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using KMF.Common;

namespace KMF.DAL
{
    public partial class ProductCommentDb
    {

        public static List<ProductCommentListDetailDto> GetProductCommentByProductIdPagging(int page, int itemsPerPage, ref int totalPage,string pId,int sort)
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_ProductComment_GetByProductIdPaging");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@Page", page));
                command.Parameters.Add(dao.CreateParameter("@ItemsPerPage", itemsPerPage));
                SqlParameter itemTotalPage = command.Parameters.Add("@TotalPage", SqlDbType.Int);
                command.Parameters.Add(dao.CreateParameter("@ProductId", pId));
                command.Parameters.Add(dao.CreateParameter("@Sort", sort));
                itemTotalPage.Direction = ParameterDirection.Output;

                var result = dao.GetDTOList<ProductCommentListDetailDto>(ref command);
                totalPage = int.Parse(itemTotalPage.Value.ToString() == "" ? "0" : itemTotalPage.Value.ToString());
                return result;
            }
            finally
            {
                command.Connection.Close();
            }
        }


    }
}
